package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.MarshallingEntity;
import com.my12306.train.model.vo.MarshallingCarriageVo;
import com.my12306.train.service.MarshallingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 列车编组基本信息表
 *
 * @author ËÕÄÁÏ¦
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/marshalling")
public class MarshallingController {
    @Autowired
    private MarshallingService marshallingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResponseData list(@RequestParam Map<String, Object> params) {
        PageUtils page = null;
        return ResponseData.ok().put("page", page);
    }

    /**
     * 查询全部
     */
    @PostMapping("/queryAll")
    public ResponseData queryAll(@RequestBody PageVo pageVo) {
        List<MarshallingCarriageVo> marshallingCarriageVos = marshallingService.queryAllMarshallingByParams(pageVo);
        return ResponseData.ok().put("list", marshallingCarriageVos);
    }

    /**
     * 查询某个编组
     */
    @PostMapping("/queryMarshallingById")
    public ResponseData queryMarshallingById(@RequestParam Long id) {
        MarshallingCarriageVo marshallingCarriageVo = marshallingService.queryAllMarshallingById(id);
        return ResponseData.ok().put("marshalling", marshallingCarriageVo);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{groupId}")
    public ResponseData info(@PathVariable("groupId") Long groupId) {
        MarshallingEntity marshalling = marshallingService.getById(groupId);

        return ResponseData.ok().put("marshalling", marshalling);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ResponseData save(@RequestBody MarshallingEntity marshalling) {
        marshallingService.saveMarshalling(marshalling);
        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public ResponseData update(@RequestBody MarshallingEntity marshalling) {
        marshallingService.updateById(marshalling);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody Long[] groupIds) {
        marshallingService.removeByIds(Arrays.asList(groupIds));

        return ResponseData.ok();
    }
    /**
     * 查询未绑定的编组
     */
    @GetMapping("/queryMarshallingNoMar")
    public ResponseData queryMarshallingNoMar() {
        List<MarshallingEntity> marshalling = marshallingService.queryMarshallingNoMar();
        return ResponseData.ok().put("marshalling", marshalling);
    }
}
